
#ifndef _PROCESSORSYSTEMRRR_
#define _PROCESSORSYSTEMRRR_

#include <stdio.h>
#include <sys/time.h>

#include "asim/provides/low_level_platform_interface.h"
//#include "asim/provides/funcp_simulated_memory.h"
#include "asim/provides/rrr.h"

// wjun
#define TYPES_ONLY
#include "awb/rrr/server_stub_PROCESSORSYSTEMRRR.h"
#undef TYPES_ONLY
//#include "asim/rrr/client_stub_PROCESSORSYSTEMRRR.h"

#define TAG_MATCH 0
#define TAG_STEP 1
#define TAG_REG 2
#define TAG_MEMREAD 3 
#define TAG_MEMWRITE 4
#define COMPR_BUFF_SIZE (1024*8)

typedef class PROCESSORSYSTEMRRR_SERVER_CLASS* PROCESSORSYSTEMRRR_SERVER;
class PROCESSORSYSTEMRRR_SERVER_CLASS: public RRR_SERVER_CLASS, public PLATFORMS_MODULE_CLASS
{
  private:
    // self-instantiation
    static PROCESSORSYSTEMRRR_SERVER_CLASS instance;
    //FUNCP_SIMULATED_MEMORY_CLASS *memory;   

 
    // server stub
    RRR_SERVER_STUB serverStub;
//    PROCESSORSYSTEMRRR_CLIENT_STUB clientStub;

//    int count;    
		// wjun
		unsigned int *compr_buff;
		unsigned int compr_buff_idx;
		unsigned char compr_buff_lowhalf_loaded;
		unsigned char compr_buff_highhalf_loaded;
		unsigned int compr_buff_loaded;

		unsigned int pc;
		unsigned int ioffset;
		unsigned int isize;
		unsigned int *idata;
		FILE* fcompressed;
		FILE* fdinerofifo;
		FILE* fdecomprstring;
		FILE* fdecomprbin;

		unsigned int decompr_instr_count;


  public:
    PROCESSORSYSTEMRRR_SERVER_CLASS();
    ~PROCESSORSYSTEMRRR_SERVER_CLASS();

    // static methods
    static PROCESSORSYSTEMRRR_SERVER GetInstance() { return &instance; }

    // required RRR methods
    void Init(PLATFORMS_MODULE);
    void Uninit();
    void Cleanup();

    //
    // RRR service methods
    //

//   UINT32 MemoryRequestLoad  (UINT32 address);
//   void   MemoryRequestStore (UINT32 address, UINT32 data);
   

		// wjun
		//UINT32 InstrRequestLoad  (UINT32 address);
		OUT_TYPE_InstrRequestLoad InstrRequestLoad  (UINT32 address);
//		void ReqCompressed(UINT32 avail);
		//OUT_TYPE_ReqCompressed ReqCompressed(UINT32 a);
		void SendResult(UINT32 flags1, UINT32 addr1, UINT32 value1, UINT32 pc1, 
				UINT32 flags2, UINT32 addr2, UINT32 value2, UINT32 pc2, 
				UINT32 flags3, UINT32 addr3, UINT32 value3, UINT32 pc3,
				UINT32 flags4, UINT32 addr4, UINT32 value4, UINT32 pc4); 
		bool SingleCompressed(unsigned int* rv);
};



// include server stub
#include "asim/rrr/server_stub_PROCESSORSYSTEMRRR.h"

#endif
